import MonoSingle from "../Utility/MonoSingle";
import TvBoxInput, {inputDirectionKey, inputKeyCode} from "./TvBoxInput";

const { ccclass, property } = cc._decorator;
@ccclass
export default class TvBoxDemo extends cc.Component {
    @property(cc.Label)
    tex_tips: cc.Label = null
    private index: number = 0;
    protected start(): void {
        let self = this;
        if (this.tex_tips) {
            this.schedule(function () {
                self.index = self.index + 1;
                if (self.index > 100)
                    self.index = 0;
                self.tex_tips.string = "方向按键移动" + self.index;
            }, 0.2);
        }

        MonoSingle.GetTvBoxInput().addInputDirection(this.name + "inputDirectionEvent", function (forword, directionKey) {
            self.inputDirectionEvent(forword, directionKey);
        });
        MonoSingle.GetTvBoxInput().addKeycodeNumAction(this.name + "KeycodeNumAction", function (keyCode) {
            MonoSingle.canvasNode.getChildByName("tex_tips").getComponent(cc.Label).string = "数字键::"+keyCode;
        });
    }
    inputDirectionEvent(forword: any, directionKey: any): void {
        let speed = 5;
        let forwardx = this.tex_tips.node.getPosition().x + forword.x * speed
        let forwardy = this.tex_tips.node.getPosition().y + forword.y * speed
        this.tex_tips.node.setPosition(forwardx, forwardy)
    }
}
